//
//  MBSpaceController.m
//  mibaotu
//
//  Created by 彭康 on 16/9/14.
//  Copyright © 2016年 pegnk. All rights reserved.
//

#import "MBSpaceController.h"
#import "MBSpaceUserViewController.h"
#import "MBSpaceSetUpNewViewController.h"
#import "MBSpaceMusicClassViewController.h"
#import "MBSpaceMyCollectionViewController.h"
#import "MBSpaceParentChildShowClassViewController.h"
#import "MBSpaceDownedMusicViewController.h"
#import "MBSpaceDowningMusicViewController.h"
#import "MBSongDetailController.h"
#import "MBSpaceSetViewController.h"
#import "MBLoginController.h"
#import "MBNavController.h"
#import "MBSpaceSetUpNewDetailViewController.h"

#import "MBSpaceHeaderView.h"

@interface MBSpaceController ()<UITableViewDataSource,UITableViewDelegate,MBSpaceHeaderViewDelegate> {
    UITableView             *_tableView;
    MBSpaceHeaderView       *_tableHeaderView;
    NSMutableArray          *_mutCunstomFileArr; //保存自定义文件
    NSMutableArray          *_downedMusicClassArr; //下载的歌曲分类显示数组
}

@end

@implementation MBSpaceController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
    [self onLoadData];
    if (ISIPAD) {
        [self onUpdateUIForView:self.orientation];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    _mutCunstomFileArr = [[NSMutableArray alloc]init];
    _downedMusicClassArr = [[NSMutableArray alloc]init];
    
    [self setNavBar];
    [self onCreateUI];
    
}

#pragma mark - Actions
#pragma mark - UI
- (void)setNavBar
{
    [self setTitleView:@"米宝空间"];
    UIButton *lbt = [UIButton buttonWithType:UIButtonTypeCustom];
    lbt.frame = CGRectMake(0, 0, 60, 30);
    [lbt setImage:[UIImage imageNamed:@"shezhi"] forState:UIControlStateNormal];
    [lbt setImage:[UIImage imageNamed:@"shezhi"] forState:UIControlStateHighlighted];
    [lbt setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 30)];
    [lbt addTarget:self action:@selector(onSelectItemForSet) forControlEvents:UIControlEventTouchUpInside];
    [self setLeftBarItem:lbt];
    
    [self setRightPlayerItem];
}

- (void)onCreateUI
{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
    if (ISIPAD) {
        if (self.orientation != UIDeviceOrientationPortrait) {
            //不是竖屏启动
            _tableView.frame = CGRectMake(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);
        }
    }
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.backgroundView = nil;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
    _tableView.tableHeaderView = [self setUpTableHeaderView];
    _tableView.tableFooterView = [self setUpTableFooterView];
}

- (MBSpaceHeaderView *)setUpTableHeaderView
{
    if (!_tableHeaderView) {
        _tableHeaderView = [[MBSpaceHeaderView alloc]initWithFrame:CGRectMake(0, 0, _tableView.width, 320*PERCEN)];
        _tableHeaderView.delegate = self;
    }
//    if (ISIPAD) {        
        _tableHeaderView.width = _tableView.width;
        _tableHeaderView.orientation = self.orientation;
//    }
    return _tableHeaderView;
}

- (UIView *)setUpTableFooterView
{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0*PERCEN, SCREEN_WIDTH, 120*PERCEN)];
    bgView.backgroundColor = [UIColor clearColor];
    
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0*PERCEN, bgView.width, 80*PERCEN)];
    contentView.backgroundColor = [UIColor whiteColor];
    [bgView addSubview:contentView];
    
    UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
    bt.frame = CGRectMake((contentView.width-100)/2., 0, 100, contentView.height);
    bt.backgroundColor = [UIColor clearColor];
    [bt setTitle:@"新建分类" forState:UIControlStateNormal];
    [bt setTitle:@"新建分类" forState:UIControlStateHighlighted];
    [bt setTitleColor:UIColorFromHex(0x333333) forState:UIControlStateNormal];
    [bt setTitleColor:UIColorFromHex(0x333333) forState:UIControlStateHighlighted];
    bt.titleLabel.font = [UIFont systemFontOfSize:14.f];
    UIImage *img = [UIImage imageNamed:@"xinjianfl_kj"];
    [bt setImage:img forState:UIControlStateNormal];
    [bt setImage:img forState:UIControlStateHighlighted];
    [bt setImageEdgeInsets:UIEdgeInsetsMake((contentView.height-img.size.height)/2., 5, (contentView.height-img.size.height)/2., bt.width-img.size.width-5)];
    [bt addTarget:self action:@selector(onSelectForNewCellAction) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:bt];
    
    return bgView;
}

//设置
- (void)onSelectItemForSet
{
    MBSpaceSetViewController *song = [[MBSpaceSetViewController alloc]init];
    [self.navigationController pushViewController:song animated:YES];
}

- (void)onSelectItemForWork
{
    [self onPlayMusic];
}

//加载数据
- (void)onLoadData
{
    UserModel *model = [UserManager standerDefult].userModel;
    if (model) {
        [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:SPACE_GETLISTALBUM_URL_PATH,model.UserID] view:nil success:^(NSDictionary * json) {
            if(![json isKindOfClass:[NSDictionary class]])return ;
            if ([json[@"ret_code"] integerValue]==0) {
                NSArray *arr = json[@"data"];
                if (arr.count > 0) {
                    /*
                     {
                     "CateID": 36,
                     "CateName": "Tt ",
                     "CateType": 2
                     }
                     */
                    
                    [_mutCunstomFileArr removeAllObjects];
                    NSMutableArray *arr1 = [[NSMutableArray alloc]init];
                    NSMutableArray *arr2 = [[NSMutableArray alloc]init];
                    for (NSDictionary *dic in arr) {
                        if ([[NSString stringWithFormat:@"%@",[dic objectForKey:@"CateType"]] isEqualToString:@"1"]) {
                            [arr1 addObject:dic];
                        }
                        if ([[NSString stringWithFormat:@"%@",[dic objectForKey:@"CateType"]] isEqualToString:@"2"]) {
                            [arr2 addObject:dic];
                        }
                    }
                    [_mutCunstomFileArr addObject:arr1];
                    [_mutCunstomFileArr addObject:arr2];
                    
                    [[UserManager standerDefult].spaceFileArr removeAllObjects];
                    [[UserManager standerDefult].spaceFileArr addObjectsFromArray:_mutCunstomFileArr];
                    [_tableView reloadData];
                }
               
            } else {
                [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
            }
        } failure:^(NSError *error) {
            
        }];
    }
    
    _tableHeaderView.text = ([UserManager standerDefult].userModel.UserID ? YES : NO);
    NSArray *sessionModels = [NSKeyedUnarchiver unarchiveObjectWithFile:DownloadDetailPath];
//    NSArray *sessionModels = [NSKeyedUnarchiver unarchiveObjectWithFile:[MusicCachesDirectory stringByAppendingPathComponent:@"downingloadDetail.data"]];
    _tableHeaderView.downingMusic = [NSString stringWithFormat:@"%d",(int)(sessionModels.count)];//[[[DownManager staredInstance]currentDownloads] count]+
    NSArray *downedQZXMusicArr = [[FMManageObject standerDefault]onSelectLocalParentChildShowCount];
    _tableHeaderView.downedMusic = [NSString stringWithFormat:@"%d",(int)([[UserManager standerDefult].downedMusicArr count]+downedQZXMusicArr.count)];
    NSArray *recentMusicArr = [[FMManageObject standerDefault]onSelectMusicPlayForRecent];
    _tableHeaderView.playedMusic = [NSString stringWithFormat:@"%d",(int)recentMusicArr.count];
    
    [_tableView reloadData];
}

- (void)onUpdateUIForView:(UIDeviceOrientation)orientation
{
    _tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    _tableView.tableHeaderView = [self setUpTableHeaderView];
    _tableView.tableFooterView = [self setUpTableFooterView];
    [_tableView reloadData];
}

#pragma mark - 新建分类
- (void)onSelectForNewCellAction
{
    if (![UserManager standerDefult].userModel.UserID) {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
        return;
    }
    
    MBSpaceSetUpNewViewController *newView = [[MBSpaceSetUpNewViewController alloc]init];
    [self.navigationController pushViewController:newView animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 6;
    }
    if (_mutCunstomFileArr.count == 0) {
        return 0;
    }
    NSArray *arr = [_mutCunstomFileArr lastObject];
    return arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"MBSpaceHomeCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.accessoryType = UITableViewCellAccessoryNone;
        
        UIImageView *headImgView = [[UIImageView alloc]initWithFrame:CGRectMake((ISIPAD ? 460*PERCEN*(ISPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.) : 25*PERCEN), 32.5*PERCEN, 35*PERCEN, 35*PERCEN)];
        headImgView.backgroundColor = [UIColor clearColor];
        headImgView.tag = 100;
        [cell.contentView addSubview:headImgView];
        
        UILabel *titleLb = [[UILabel alloc]initWithFrame:CGRectMake(headImgView.right+20*PERCEN, (100*PERCEN-30)/2., 120, 30)];
        titleLb.backgroundColor = [UIColor clearColor];
        titleLb.textAlignment = NSTextAlignmentLeft;
        titleLb.textColor = [UIColor blackColor];
        titleLb.font = [UIFont systemFontOfSize:14.f];
        titleLb.tag = 101;
        [cell.contentView addSubview:titleLb];
        
        UIImage *rightImg = [UIImage imageNamed:@"arrow"];
        UIImageView *rightView= [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-(ISIPAD?460*PERCEN*(ISPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN)-rightImg.size.width, (100*PERCEN-rightImg.size.height)/2., rightImg.size.width, rightImg.size.height)];
        rightView.backgroundColor = [UIColor clearColor];
        rightView.image = rightImg;
        rightView.tag = 104;
        [cell.contentView addSubview:rightView];
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake((ISIPAD?440*PERCEN*(ISPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0), 100*PERCEN-1, SCREEN_WIDTH-2*(ISIPAD?440*PERCEN*(ISPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0), 1)];
        lineView.backgroundColor = [UIColorFromHex(0xcccccc)colorWithAlphaComponent:.35];
        lineView.tag = 102;
        [cell.contentView addSubview:lineView];
        
        //增加删除按钮
        UIView *deleteBgView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, 100*PERCEN)];
        deleteBgView.backgroundColor = TINK_BG_COLOR;
        deleteBgView.tag = 103;
        [cell.contentView addSubview:deleteBgView];
        
        UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        deleteBtn.frame = CGRectMake(0, 0, 140*PERCEN, deleteBgView.height);
        [deleteBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        [deleteBgView addSubview:deleteBtn];
    }
    cell.width = tableView.width;
    
    UIImageView *headImgView =  (UIImageView *)[cell viewWithTag:100];
    UILabel *titleLb =  (UILabel *)[cell viewWithTag:101];
    UIView *lineView =  (UIView *)[cell viewWithTag:102];
    UIView *deleteBgView = (UIView *)[cell viewWithTag:103];
    UIImageView *rightView =  (UIImageView *)[cell viewWithTag:104];
    deleteBgView.backgroundColor = TINK_BG_COLOR;
    deleteBgView.left = (ISIPAD?tableView.width:SCREEN_WIDTH);
    
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
            {
                headImgView.image = [UIImage imageNamed:@"shoucang_kj"];
                headImgView.frame = CGRectMake((ISIPAD ? 460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.) : 25*PERCEN), (100*PERCEN - 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width)/2., 35*PERCEN, 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width);
                titleLb.text = @"收藏";
            }
                break;
            case 1:
            {
                headImgView.image = [UIImage imageNamed:@"erge_kj"];
                headImgView.frame = CGRectMake((ISIPAD ? 460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.) : 25*PERCEN), (100*PERCEN - 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width)/2., 35*PERCEN, 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width);
                titleLb.text = @"儿歌";
            }
                break;
            case 2:
            {
                headImgView.image = [UIImage imageNamed:@"guoxue_kj"];
                headImgView.frame = CGRectMake((ISIPAD ? 460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.) : 25*PERCEN), (100*PERCEN - 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width)/2., 35*PERCEN, 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width);
                titleLb.text = @"国学";
            }
                break;
            case 3:
            {
                headImgView.image = [UIImage imageNamed:@"gushi_kj"];
                headImgView.frame = CGRectMake((ISIPAD ? 460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.) : 25*PERCEN), (100*PERCEN - 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width)/2., 35*PERCEN, 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width);
                titleLb.text = @"故事";
            }
                break;
            case 4:
            {
                headImgView.image = [UIImage imageNamed:@"yingwen_kj"];
                headImgView.frame = CGRectMake((ISIPAD ? 460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.) : 25*PERCEN), (100*PERCEN - 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width)/2., 35*PERCEN, 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width);
                titleLb.text = @"英文";
            }
                break;
            case 5:
            {
                headImgView.image = [UIImage imageNamed:@"qinzixiu_kj"];
                headImgView.frame = CGRectMake((ISIPAD ? 460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.) : 25*PERCEN), (100*PERCEN - 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width)/2., 35*PERCEN, 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width);
                titleLb.text = @"亲子秀";
                lineView.hidden = YES;
            }
                break;
                
            default:
                break;
        }
    }
    else if (indexPath.section == 1) {
        //自定义
        NSArray *sectionArr = [_mutCunstomFileArr lastObject];
        NSDictionary *fileDic = [sectionArr objectAtIndex:indexPath.row];
        headImgView.image = [UIImage imageNamed:@"fenlei_zy"];
        headImgView.frame = CGRectMake((ISIPAD ? 460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.) : 25*PERCEN), (100*PERCEN - 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width)/2., 35*PERCEN, 35*PERCEN*headImgView.image.size.height/headImgView.image.size.width);
        titleLb.text = [[fileDic objectForKey:@"CateName"]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    
    if (ISIPAD) {
        titleLb.left = headImgView.right+20*PERCEN;
        lineView.left = (ISIPAD?440*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):0);
        lineView.width = self.view.width - 2*lineView.left;
        UIImage *rightImg = [UIImage imageNamed:@"arrow"];
        rightView.left = self.view.width-(ISIPAD?460*PERCEN*(self.orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN)-rightImg.size.width;
    } else {
        titleLb.frame = CGRectMake(headImgView.right+20*PERCEN, (100*PERCEN-30)/2., 200, 30);
        lineView.frame = CGRectMake(0, 100*PERCEN-1, SCREEN_WIDTH, 1);
        UIImage *rightImg = [UIImage imageNamed:@"arrow"];
        rightView.frame = CGRectMake(SCREEN_WIDTH-25*PERCEN-rightImg.size.width, (100*PERCEN-rightImg.size.height)/2., rightImg.size.width, rightImg.size.height);
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100*PERCEN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 20*PERCEN;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        return YES;
    }
    return NO;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self onDeleteCustomCellWithIndexPath:indexPath withTableView:tableView];
    }
}

- (void)onDeleteCustomCellWithIndexPath:(NSIndexPath *)indexPath withTableView:(UITableView *)tableView
{

    UserModel *model = [UserManager standerDefult].userModel;
    if (model) {
        if (_mutCunstomFileArr.count > indexPath.section) {
            NSMutableArray *mutArr = [_mutCunstomFileArr objectAtIndex:indexPath.section];
            if (mutArr.count > indexPath.row) {
                
                NSDictionary *fileDic = [mutArr objectAtIndex:indexPath.row];
                
                [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:SPACE_REMOVEALBUM_URL_PATH,model.UserID,[NSNumber numberWithInt:[fileDic[@"CateID"] intValue]]] view:nil success:^(NSDictionary * json) {
                    if ([json[@"ret_code"] integerValue]==0) {
                        
                        [mutArr removeObjectAtIndex:indexPath.row];
                        UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
                        UIView *deleteBgView = (UIView *)[cell viewWithTag:103];
                        deleteBgView.backgroundColor = [UIColor whiteColor];
                        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
                        
                    } else {
                        [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
                    }
                } failure:^(NSError *error) {
                    
                }];
            }
        }
    } else {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UserModel *model = [UserManager standerDefult].userModel;
    if (model) {
     
        [self onPushViewControlWithIndexPath:indexPath];
        
    } else {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
    }
}

- (void)onPushViewControlWithIndexPath:(NSIndexPath *)indexPath
{
    //文件里面有音频
    if (indexPath.section == 0) {
        NSArray *fileArr = [_mutCunstomFileArr firstObject];
        if ([fileArr firstObject] == nil) {
            return;
        }
        NSDictionary *fileDic = [fileArr objectAtIndex:0];
        for (NSDictionary *dic in fileArr) {
            NSString *title = @"儿歌";
            if (indexPath.row == 1) {
                title = @"儿歌";
            }
            else if (indexPath.row == 2) {
                title = @"国学";
            }
            else if (indexPath.row == 3) {
                title = @"故事";
            }
            else if (indexPath.row == 4) {
                title = @"英文";
            }
            else if (indexPath.row == 5) {
                title = @"亲子秀";
            }
            NSString *CateName = [[dic objectForKey:@"CateName"]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            if ([title isEqualToString:CateName]) {
                fileDic = dic;
            }
        }
        
        if (indexPath.row == 0) {
            MBSpaceMyCollectionViewController *collection = [[MBSpaceMyCollectionViewController alloc]init];
            collection.type = MBSpaceMyCollectionShowType_Collection;
            [self.navigationController pushViewController:collection animated:YES];
        }
        else if (indexPath.row == 1 ) {
            MBSpaceMusicClassViewController *music = [[MBSpaceMusicClassViewController alloc]init];
            music.type = MusicClassType_ErGe;
             music.dataDic = fileDic;
            [self.navigationController pushViewController:music animated:YES];
        }
        else if (indexPath.row == 2 ) {
            MBSpaceMusicClassViewController *music = [[MBSpaceMusicClassViewController alloc]init];
            music.type = MusicClassType_GuoXue;
             music.dataDic = fileDic;
            [self.navigationController pushViewController:music animated:YES];
        }
        else if (indexPath.row == 3 ) {
            MBSpaceMusicClassViewController *music = [[MBSpaceMusicClassViewController alloc]init];
            music.type = MusicClassType_GuShi;
             music.dataDic = fileDic;
            [self.navigationController pushViewController:music animated:YES];
        }
        else if (indexPath.row == 4 ) {
            MBSpaceMusicClassViewController *music = [[MBSpaceMusicClassViewController alloc]init];
            music.type = MusicClassType_YingWen;
             music.dataDic = fileDic;
            [self.navigationController pushViewController:music animated:YES];
        }
        else if (indexPath.row == 5) {
            MBSpaceMusicClassViewController *music = [[MBSpaceMusicClassViewController alloc]init];
            music.type = MusicClassType_QinZiXiu;
            music.dataDic = fileDic;
            [self.navigationController pushViewController:music animated:YES];
            
        }
    }
    else if (indexPath.section == 1) {
        NSArray *fileArr = [_mutCunstomFileArr lastObject];
        NSDictionary *fileDic = [fileArr objectAtIndex:indexPath.row];
        MBSpaceMusicClassViewController *music = [[MBSpaceMusicClassViewController alloc]init];
        music.type = MusicClassType_Custom;
        music.dataDic = fileDic;
        music.albumName = [[fileDic objectForKey:@"CateName"]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [self.navigationController pushViewController:music animated:YES];
    }
}

//MARK:表格头部代理
- (void)onSelectItemForLoginWithView:(MBSpaceHeaderView *)view
{
    NSLog(@"登录");
    if (![UserManager standerDefult].userModel.UserID) {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
    }
}

- (void)onselectItemForUserWithView:(MBSpaceHeaderView *)view
{
    self.tabBarController.tabBar.hidden=YES;
    self.hidesBottomBarWhenPushed=YES;
    MBSpaceUserViewController *user = [[MBSpaceUserViewController alloc]init];
    user.customFileArr = _mutCunstomFileArr;
    [self.navigationController pushViewController:user animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}

- (void)onSelectITemForDowningWithView:(MBSpaceHeaderView *)view
{
        NSLog(@"正在下载");
    MBSpaceDowningMusicViewController *downing = [[MBSpaceDowningMusicViewController alloc]init];
    [self.navigationController pushViewController:downing animated:YES];
}

- (void)onSelectITemForDownedWithView:(MBSpaceHeaderView *)view
{
        NSLog(@"已下载");
    MBSpaceDownedMusicViewController *downMusic = [[MBSpaceDownedMusicViewController alloc]init];
    downMusic.type = MBSpaceDownedMusicType_Downed;
    [self.navigationController pushViewController:downMusic animated:YES];
}

- (void)onSelectITemForUsedWithView:(MBSpaceHeaderView *)view
{
        NSLog(@"最近使用");
    MBSpaceDownedMusicViewController *downMusic = [[MBSpaceDownedMusicViewController alloc]init];
    downMusic.type = MBSpaceDownedMusicType_Visit;
    [self.navigationController pushViewController:downMusic animated:YES];
}

@end
